package main

import (
	"github.com/nacos-group/nacos-sdk-go/clients"
	"github.com/nacos-group/nacos-sdk-go/clients/naming_client"
	"github.com/nacos-group/nacos-sdk-go/common/constant"
	"github.com/nacos-group/nacos-sdk-go/vo"
)
var Client naming_client.INamingClient
func InitConfig() {

	sc := []constant.ServerConfig{
		{
			IpAddr: "192.168.0.108",
			Port:   8848,
		},
	}
	//or a more graceful way to create ServerConfig
	_ = []constant.ServerConfig{
		*constant.NewServerConfig("192.168.0.108", 8848),
	}

	cc := constant.ClientConfig{
		NamespaceId:         "a0cb9cb4-8593-4c92-ab22-8e7173154f42", //namespace id
		TimeoutMs:           5000,
		NotLoadCacheAtStart: true,
		LogDir:              "/tmp/logs/nacos/log",
		CacheDir:            "/tmp/caches/nacos/cache",
		LogRollingConfig: &constant.ClientLogRollingConfig{
			MaxSize: 1,
		},
		LogLevel: "debug",
	}
	//or a more graceful way to create ClientConfig
	_ = *constant.NewClientConfig(
		constant.WithNamespaceId("a0cb9cb4-8593-4c92-ab22-8e7173154f42"),
		constant.WithTimeoutMs(5000),
		constant.WithNotLoadCacheAtStart(true),
		constant.WithLogDir("/tmp/nacos/log"),
		constant.WithCacheDir("/tmp/nacos/cache"),
		constant.WithLogLevel("debug"),
		constant.WithLogRollingConfig(&constant.ClientLogRollingConfig{MaxSize: 1}),
	)

	// a more graceful way to create naming client
	var err error
	Client, err = clients.NewNamingClient(
		vo.NacosClientParam{
			ClientConfig:  &cc,
			ServerConfigs: sc,
		},
	)

	if err != nil {
		panic(err)
	}
}
